package com.neu.his.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neu.his.mapper.DrugDisturbMapper;
import com.neu.his.mapper.DrugMapper;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

@Data
public class DrugDisturb extends Base {
    @TableField(exist = false)
    @Autowired
    DrugMapper drugMapper;

    private Long drugId;
    private Long diagId;
    private Integer num;
    private BigDecimal totalCount;
    private boolean haveDeliver;
    private BigDecimal realCount;

    public void setInit() {
        countTotal();
        haveDeliver = false;
        realCount = new BigDecimal(0);
    }

    public void countTotal(){
        Drug drug = drugMapper.selectOne(new QueryWrapper<Drug>().eq("id", drugId));
        totalCount = new BigDecimal(drug.getDrugPrice().intValue() * num);
    }

    @TableField(exist = false)
    private DiagRecords diagRecords;

    @TableField(exist = false)
    private Drug drug;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

}
